package com.yehui.alibaba.service.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author 业徽
 * @date 2021/8/4
 */
@LocalTCC
public interface TCCProductService {

    /**
     * 扣减库存
     *
     * @param productId 商品 ID
     * @param amount    扣减数量
     * @throws Exception 扣减失败时抛出异常
     */
    @TwoPhaseBusinessAction(name = "ProductServiceTCC", commitMethod = "tccCommit", rollbackMethod = "tccRollback")
    void reduceStock(BusinessActionContext actionContext, Long productId, Integer amount) throws Exception;

    /**
     * Commit boolean.
     *
     * @param actionContext the action context
     * @return the boolean
     */
    boolean tccCommit(BusinessActionContext actionContext);

    /**
     * Rollback boolean.
     *
     * @param actionContext the action context
     * @return the boolean
     */
    boolean tccRollback(BusinessActionContext actionContext);


}
